package com.codeazur.as3swf.data
{
   import com.codeazur.as3swf.SWFData;
   import flash.geom.ColorTransform;
   
   public class SWFColorTransformWithAlpha extends SWFColorTransform
   {
       
      
      public function SWFColorTransformWithAlpha(param1:SWFData = null)
      {
         super(param1);
      }
      
      public function get aMult() : Number
      {
         return _aMult / 256;
      }
      
      public function set aMult(param1:Number) : void
      {
         _aMult = clamp(param1 * 256);
         this.updateHasMultTerms();
      }
      
      public function get aAdd() : Number
      {
         return _aAdd;
      }
      
      public function set aAdd(param1:Number) : void
      {
         _aAdd = clamp(param1);
         this.updateHasAddTerms();
      }
      
      override public function get colorTransform() : ColorTransform
      {
         return new ColorTransform(rMult,gMult,bMult,this.aMult,rAdd,gAdd,bAdd,this.aAdd);
      }
      
      override public function parse(param1:SWFData) : void
      {
         var _loc2_:uint = 0;
         param1.resetBitsPending();
         hasAddTerms = param1.readUB(1) == 1;
         hasMultTerms = param1.readUB(1) == 1;
         _loc2_ = param1.readUB(4);
         if(hasMultTerms)
         {
            _rMult = param1.readSB(_loc2_);
            _gMult = param1.readSB(_loc2_);
            _bMult = param1.readSB(_loc2_);
            _aMult = param1.readSB(_loc2_);
         }
         else
         {
            _rMult = 256;
            _gMult = 256;
            _bMult = 256;
            _aMult = 256;
         }
         if(hasAddTerms)
         {
            _rAdd = param1.readSB(_loc2_);
            _gAdd = param1.readSB(_loc2_);
            _bAdd = param1.readSB(_loc2_);
            _aAdd = param1.readSB(_loc2_);
         }
         else
         {
            _rAdd = 0;
            _gAdd = 0;
            _bAdd = 0;
            _aAdd = 0;
         }
      }
      
      override public function publish(param1:SWFData) : void
      {
         param1.resetBitsPending();
         param1.writeUB(1,!!hasAddTerms?uint(1):uint(0));
         param1.writeUB(1,!!hasMultTerms?uint(1):uint(0));
         var _loc2_:Array = [];
         if(hasMultTerms)
         {
            _loc2_.push(_rMult,_gMult,_bMult,_aMult);
         }
         if(hasAddTerms)
         {
            _loc2_.push(_rAdd,_gAdd,_bAdd,_aAdd);
         }
         var _loc3_:uint = hasMultTerms || hasAddTerms?uint(param1.calculateMaxBits(true,_loc2_)):uint(1);
         param1.writeUB(4,_loc3_);
         if(hasMultTerms)
         {
            param1.writeSB(_loc3_,_rMult);
            param1.writeSB(_loc3_,_gMult);
            param1.writeSB(_loc3_,_bMult);
            param1.writeSB(_loc3_,_aMult);
         }
         if(hasAddTerms)
         {
            param1.writeSB(_loc3_,_rAdd);
            param1.writeSB(_loc3_,_gAdd);
            param1.writeSB(_loc3_,_bAdd);
            param1.writeSB(_loc3_,_aAdd);
         }
      }
      
      override public function clone() : SWFColorTransform
      {
         var _loc1_:SWFColorTransformWithAlpha = new SWFColorTransformWithAlpha();
         _loc1_.hasAddTerms = hasAddTerms;
         _loc1_.hasMultTerms = hasMultTerms;
         _loc1_.rMult = rMult;
         _loc1_.gMult = gMult;
         _loc1_.bMult = bMult;
         _loc1_.aMult = this.aMult;
         _loc1_.rAdd = rAdd;
         _loc1_.gAdd = gAdd;
         _loc1_.bAdd = bAdd;
         _loc1_.aAdd = this.aAdd;
         return _loc1_;
      }
      
      override protected function updateHasMultTerms() : void
      {
         hasMultTerms = _rMult != 256 || _gMult != 256 || _bMult != 256 || _aMult != 256;
      }
      
      override protected function updateHasAddTerms() : void
      {
         hasAddTerms = _rAdd != 0 || _gAdd != 0 || _bAdd != 0 || _aAdd != 0;
      }
      
      override public function toString() : String
      {
         return "(" + rMult + "," + gMult + "," + bMult + "," + this.aMult + "," + rAdd + "," + gAdd + "," + bAdd + "," + this.aAdd + ")";
      }
   }
}
